package com.diankangwo.factory.service.impl;

import com.diankangwo.factory.dao.TdClassificationMapper;
import com.diankangwo.factory.entity.TdClassification;
import com.diankangwo.factory.service.TdClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/** 二级分类
 * Created by wuye on 2017/9/11.
 */
@Service("TdClassificationService")
public class TdClassificationServiceImpl implements TdClassificationService{

    @Autowired
    private TdClassificationMapper mapper;

    /**
     * 保存二级分类
     * @param tdClassification
     */
    @Override
    @Transactional
    public int save(TdClassification tdClassification) {
        tdClassification.setClasstime(new Date());
        tdClassification.setIsdelete(0);
        tdClassification.setClassorder(0);
        return mapper.insert(tdClassification);
    }

    /**
     * 查询所有二级分类
     * @return
     */
    @Override
    public List<TdClassification> queryAll() {
        return mapper.queryAll();
    }

    /**
     * 根据一级分类查询所有二级分类
     * @return
     */
    @Override
    public List<TdClassification> queryByTpesId(int typesId) {
        return mapper.queryByTypeId(typesId);
    }

    /**
     * 批量删除
     * @param typeId
     */
    @Override
    @Transactional
    public void deleteBatch(int typeId) {
        mapper.deleteBatch(typeId);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    @Transactional
    public void delete(int id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public TdClassification selectByPrimaryKey(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }
}
